package com.xmkj.winmoney.deal;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.TextView;

import com.common.Entity.HomeEntity;
import com.common.Entity.RecentDealEntity;
import com.common.widget.recyclerview.refresh.adapter.CommonAdapter;
import com.common.widget.recyclerview.refresh.adapter.ViewHolder;
import com.xmkj.winmoney.R;
import com.xmkj.winmoney.TempItemBean;
import com.xmkj.winmoney.jifen.AwardDelActivity;
import com.xmkj.winmoney.jifen.JinPaiDetailActivity;

import java.util.List;

/**
 * Create by leo
 * 创建日期：2018/5/4
 * 描述：
 */

public class DealAdapter extends CommonAdapter<RecentDealEntity.ListsBean> {
    int type;

    public DealAdapter(Context context, List<RecentDealEntity.ListsBean> data, int position) {
        super(context, data);
        this.type = position;
    }

    @Override
    protected void convert(ViewHolder holder, final RecentDealEntity.ListsBean item, int position) {
        holder.setText(R.id.tv_time, item.opentime);
        holder.setText(R.id.tv_name, item.goodsname);
        holder.setText(R.id.tv_rate, item.schedule);
        TextView tvPrice = holder.getView(R.id.tv_price);
        TextView tvJiaRen = holder.getView(R.id.tv_chengjiao_price);
        if (item.opentype == 1) {  //成交价格  竞拍
            SpannableString spannableString = new SpannableString("成交价：" + item.deal);
            spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#FF0E41")), 4, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            tvJiaRen.setText(spannableString);
        } else {  // 夺宝
            SpannableString spannableString = new SpannableString("成交人次：" + item.deal);
            spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#FF0E41")), 5, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            tvJiaRen.setText(spannableString);
        }

        SpannableString spannableString1 = new SpannableString("市场价：" + item.goodsprice);
        spannableString1.setSpan(new ForegroundColorSpan(Color.parseColor("#FF0E41")), 4, spannableString1.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        tvPrice.setText(spannableString1);
        holder.setImageStr(R.id.iv_img,item.goodsthumb);
        if(item.opentype==1){
            holder.setText(R.id.tv_type,"竞拍夺宝");
        }else {
            holder.setText(R.id.tv_type,"一元夺宝");
        }
        holder.getParentView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(item.opentype==1){
                    Intent intent = new Intent(mContext, JinPaiDetailActivity.class);
                    HomeEntity.ListsEntity bean = new HomeEntity.ListsEntity();
                    bean.fvid = item.fvid;
                    bean.gid = item.gid ;
                    bean.vid = item.vid ;
                    intent.putExtra(JinPaiDetailActivity.INFOBEAN, bean);
                    mContext.startActivity(intent);
                }else { // 夺宝
                    Intent intent = new Intent(mContext,AwardDelActivity.class);
                    TempItemBean tempItemBean = new TempItemBean() ;

                        tempItemBean.fvid = item.fvid;
                        tempItemBean.gid = item.gid+"" ;
                        tempItemBean.vid = item.vid ;

                    intent.putExtra(AwardDelActivity.TEMPBEAN,tempItemBean);
                   mContext. startActivity(intent);
                }
            }
        });


    }

    @Override
    protected int getItemViewLayoutId(int position, RecentDealEntity.ListsBean item) {
        return R.layout.item_deal;
    }
}
